package com.song.tools.songtest.trigger;

import com.song.tools.songtest.beans.request.SysRoleUserGrantRolesRequest;
import com.song.tools.songtest.beans.request.SysUserLoginRequest;
import com.song.tools.songtest.beans.response.SysRoleUserGrantRolesResponse;
import com.song.tools.songtest.beans.response.SysUserLoginResponse;
import com.song.tools.songtest.constants.TriggerTypeEnum;
import com.song.tools.trigger.TriggerContext;
import com.song.tools.trigger.TriggerUtil;

/**
 * 用户触发器-管理器
 *
 * @author song tools
 * @since 2024-07-19
 */
public class SysUserTriggerManager {

    /**
     * 用户登录
     *
     * @param request 请求体
     * @return 登录响应体
     */
    public static SysUserLoginResponse login(SysUserLoginRequest request) {
        TriggerContext<SysUserLoginRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.USER_LOGIN, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 为用户设置角色
     *
     * @param request 请求
     * @return 响应
     */
    public static SysRoleUserGrantRolesResponse grantRolesForUser(SysRoleUserGrantRolesRequest request) {
        TriggerContext<SysRoleUserGrantRolesRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.GRANT_ROLE_FOR_USER, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }
}
